package com.labofjet.misc;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;

public class DateTest1 {
    @Test
    public void testDate() throws ParseException{
        String month = "00";
        String day = "31";
        Date d = DateUtils.parseDate("20160920", "yyyyMMdd");
        d = DateUtils.addMonths(d, Integer.parseInt(month) + 1);// 增加月份
        if ("31".equals(day)) {
            d = DateUtils.addDays(DateUtils.ceiling(d, Calendar.MONTH), -1);
        } else {
            d = DateUtils.setDays(d, Integer.parseInt(day));
        }
        System.out.println(new SimpleDateFormat("yyyyMMdd").format(d));
    }
}
